import { defineEventHandler, getRouterParam } from 'h3';
import { MOCK_VISITORS } from '~/utils/mock-data';
import { useResponseError, useResponseSuccess } from '~/utils/response';

export default defineEventHandler(async (event) => {
  const id = getRouterParam(event, 'id');

  if (!id) {
    return useResponseError('BadRequest', 'Missing visitor ID');
  }

  const visitorId = Number.parseInt(id);
  if (isNaN(visitorId)) {
    return useResponseError('BadRequest', 'Invalid visitor ID');
  }

  const visitor = MOCK_VISITORS.find((v) => v.id === visitorId);

  if (!visitor) {
    return useResponseError('NotFound', 'Visitor not found');
  }

  return useResponseSuccess(visitor);
});
